package huanghui.netstorage.servlet;

import huanghui.netstorage.util.LogUtil;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MainServlet extends HttpServlet 
{

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{

		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException 
	{
		/*String action = request.getParameter("action");
		if (action.equalsIgnoreCase("adduser"))
		{
			LogUtil.d(this, "savaUser");
			//saveUser();
		}*/
		   InputStream inputStream = request.getInputStream();
		   byte[] data = new byte[1024];
		   int len = -1;
	       
	       ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
			while ((len = inputStream.read(data, 0, 1024)) != -1)
			{		
				bout.write(data, 0, len);
			}	
			byte[] resultData = bout.toByteArray();
			bout.close();
			
			String string = new String(resultData, "gb2312");
			System.out.println(string);

		/*response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out
				.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
		out.println("<HTML>");
		out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
		out.println("  <BODY>");
		out.print("    This is ");
		out.print(this.getClass());
		out.println(", using the POST method");
		out.println("  </BODY>");
		out.println("</HTML>");
		out.flush();
		out.close();*/
	}
	
	
	/*public void saveUser()
	{
		TbUser user = new TbUser();
		user.setUserId("1");
		user.setUserName("huanghui");
		user.setUserPwd("huanghui");
		user.setUserAge(15);
		user.setUserDate(new Timestamp(System.currentTimeMillis()));
		user.setUserSex(0);
		TbUserDAO userDAO = new TbUserDAO();
		userDAO.save(user);
	}*/

}
